
package com.jf.cloud.product.controller.supplier;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.security.AuthUserContext;
import com.jf.cloud.product.dto.SpuCommDTO;
import com.jf.cloud.product.service.SpuCommService;
import com.jf.cloud.product.vo.SpuCommVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 商品评论
 *
 * @author zz
 * @date 2021-01-11 13:47:33
 */
@RestController("supplierSpuCommController")
@RequestMapping("/s/spu_comm")
@Tag(name = "商品评论")
public class SpuCommController {

    @Autowired
    private SpuCommService spuCommService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取商品评论列表" , description = "分页获取商品评论列表")
    public ServerResponseEntity<PageVO<SpuCommVO>> page(@Valid PageDTO pageDTO, @ParameterObject SpuCommDTO spuCommDTO) {
        spuCommDTO.setShopId(AuthUserContext.get().getTenantId());
        PageVO<SpuCommVO> spuCommPage = spuCommService.page(pageDTO, spuCommDTO);
        return ServerResponseEntity.success(spuCommPage);
    }

    @GetMapping
    @Operation(summary = "获取商品评论" , description = "根据spuCommId获取商品评论")
    public ServerResponseEntity<SpuCommVO> getBySpuCommId(@RequestParam Long spuCommId) {
        return ServerResponseEntity.success(spuCommService.getBySpuCommId(spuCommId));
    }

    @PutMapping
    @Operation(summary = "更新商品评论" , description = "更新商品评论")
    public ServerResponseEntity<Void> update(@Valid @RequestBody SpuCommDTO spuComm) {
        spuCommService.update(spuComm);
        return ServerResponseEntity.success();
    }
}
